using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using System.Web;

namespace viBook.Models
{ 
    public class ContentTagRepository : IContentTagRepository
    {
        viBookContext context = new viBookContext();

        public IQueryable<ContentTag> All
        {
            get { return context.ContentTags; }
        }

        public IQueryable<ContentTag> AllIncluding(params Expression<Func<ContentTag, object>>[] includeProperties)
        {
            IQueryable<ContentTag> query = context.ContentTags;
            foreach (var includeProperty in includeProperties) {
                query = query.Include(includeProperty);
            }
            return query;
        }

        public ContentTag Find(int id)
        {
            return context.ContentTags.Find(id);
        }

        public void InsertOrUpdate(ContentTag contenttag)
        {
            if (contenttag.Id == default(int)) {
                // New entity
                context.ContentTags.Add(contenttag);
            } else {
                // Existing entity
                context.Entry(contenttag).State = EntityState.Modified;
            }
        }

        public void Delete(int id)
        {
            var contenttag = context.ContentTags.Find(id);
            context.ContentTags.Remove(contenttag);
        }

        public void Save()
        {
            context.SaveChanges();
        }
    }

    public interface IContentTagRepository
    {
        IQueryable<ContentTag> All { get; }
        IQueryable<ContentTag> AllIncluding(params Expression<Func<ContentTag, object>>[] includeProperties);
        ContentTag Find(int id);
        void InsertOrUpdate(ContentTag contenttag);
        void Delete(int id);
        void Save();
    }
}